<template>
  <div class="swiper">
    <div class="center">
      <el-carousel
        :interval="4000"
        type="card"
        height="800px"
        @change="
          (pre, next) => {
            change(pre, next);
          }
        "
      >
        <el-carousel-item v-for="item in records" :key="item.id">
          <img class="img" :src="ip + item.imgUrl" alt="" />
          <p class="time">{{ item.createTime }}</p>
          <p class="name">{{ item.userName }}</p>
          <p class="job">{{ item.job }}</p>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>
import { GetAllName, GetIP } from "../api/index";
export default {
  name: "Swiper",
  data() {
    return {
      now: 1, //页数
      size: 10, //每页的数据量
      records: [],
      ip: GetIP,
      records: [],
      pages: 0, //总共页数
      current: 1, //第几页
    };
  },
  methods: {
    //获取数据
    getAllShowName() {
      GetAllName({
        now: this.now,
        size: this.size,
      }).then((res) => {
        if (res.status == 200) {
          this.records = this.records.concat(res.data.data.records);
          this.pages = res.data.data.pages;
          this.current = res.data.data.current;
        } else {
          this.$message.error("没有数据");
        }
      });
    },

    // 改变轮播图
    change(pre, next) {
      if (pre >= this.records.length - 1 && this.current < this.pages) {
        this.now += 1;
        this.getAllShowName();
      }
    },
  },
  created() {
    this.getAllShowName();
  },
};
</script>

<style scoped>
.swiper {
  background-color: #eb7072;
  width: 100%;
  height: 100%;
}
p {
  text-align: center;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  width: 400px;
  height: 500px;
  background-color: #99a9bf;
  border-radius: 5%;
  margin-top: 100px;
  margin-left: 155px;
}

.el-carousel__item:nth-child(2n + 1) {
  width: 400px;
  height: 500px;
  background-color: #d3dce6;
  border-radius: 5%;
  margin-top: 100px;
  margin-left: 155px;
}

.el-carousel__item:nth-child(2n) img {
  width: 280px;
  height: 220px;
  margin: 10px;
  text-align: center;
  border-radius: 5%;
}

.el-carousel__item:nth-child(2n + 1) img {
  width: 280px;
  height: 220px;
  margin: 10px;
  text-align: center;
  border-radius: 5%;
}
</style>